package com.example.industry.controller;

import com.example.industry.enums.TaskStatus;
import com.example.industry.service.TaskService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/task")
public class TaskController
{
    @Resource
    private TaskService taskService;

//    /**
//     * 创建任务
//     * @param projectId 任务所属的项目Id
//     * @param introduction 任务介绍
//     * @return 是否成功
//     */
//    @PostMapping(value = "/create")
//    public boolean createTask(@RequestParam(value = "projectId") Integer projectId,
//                              @RequestParam(value = "introduction") String introduction)
//    {
//        return taskService.createTask(projectId, introduction);
//    }

    /**
     * 更新任务
     * @param taskId 任务Id
     * @param introduction 任务介绍
     * @param status 任务状态(RUNNING or DONE)
     * @return 是否成功
     */
    @PutMapping(value = "/update")
    public boolean updateTask(@RequestParam(value = "taskId") Integer taskId,
                              @RequestParam(value = "introduction") String introduction,
                              @RequestParam(value = "status") TaskStatus status)
    {
        return taskService.updateTask(taskId, introduction, status);
    }

    /**
     * 删除任务
     * @param taskId 任务Id
     * @return 是否成功
     */
    @DeleteMapping(value = "/{taskId}")
    public boolean deleteTask(@PathVariable Integer taskId)
    {
        return taskService.deleteTask(taskId);
    }

    /**
     * 新建任务并分配
     * @param projectId 项目Id
     * @param introduction 任务介绍
     * @param assignerId 分配者Id
     * @param users 被分配的用户Id集合
     * @return 是否成功
     */
    @PostMapping(value = "/assign")
    public boolean assignTask(@RequestParam(value = "projectId") Integer projectId,
                              @RequestParam(value = "introduction") String introduction,
                              @RequestParam(value = "assigner") Integer assignerId,
                              @RequestParam(value = "users") List<Integer> users)
    {
        return taskService.assignTask(projectId, introduction, assignerId, users);
    }
}
